package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/userServlet")
public class UseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求和响应编码的乱码
        req.setCharacterEncoding("UTF-8");//设置请求体的解码字符集
        //设置响应体的编码字符集+设置浏览器的解码字符集
        resp.setContentType("text/html;charset=UTF-8");
        //1.获取请求参数
        String username = req.getParameter("username");
        //2.判断姓名是否已注册
        if ("zhangsan".equals(username)){
            resp.getWriter().write("{\"status\":1,\"msg\":\"用户名可用\"}");
        }else{
            resp.getWriter().write("{\"status\":0,\"msg\":\"用户名不可用\"}");
        }
    }
    /*@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }*/
}
